package pl.lsierant.j2me.bipacz.screens;

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import pl.lsierant.j2me.bipacz.BipaczMidlet;

public class SplashScreen extends Canvas implements CommandListener {
    private BipaczMidlet parent;

    private Command menuCommand;

    private Image clockImg;
    private int screenWidth;
    private int screenHeight;

    public SplashScreen(BipaczMidlet midlet) {
        parent = midlet;

        menuCommand = new Command("Menu", Command.SCREEN, 1);
        init();
    }

    protected void paint(Graphics g) {
        g.drawImage(clockImg, (screenWidth - clockImg.getWidth()) / 2, (screenHeight - clockImg.getHeight()) / 2,
                Graphics.TOP | Graphics.LEFT);
    }

    public void commandAction(Command cmd, Displayable disp) {
        if (cmd.equals(menuCommand)) {
            Display.getDisplay(parent).setCurrent(new MenuScreen(parent));
        }
    }

    private void init() {
        addCommand(menuCommand);
        setCommandListener(this);

        screenWidth = getWidth();
        screenHeight = getHeight();

        try {
            clockImg = Image.createImage("/clock.png");
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
}
